#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
const int N = 100000 + 5;
vector<pi> adj[N];
int s[N], t[N];
int main() {
  int n, m, c;
  queue<int> q;
  cin >> n >> m >> c;
  for (int i = 1; i <= n; ++i) cin >> s[i];
  for (int i = 1; i <= c; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    adj[u].emplace_back(v, w);
    t[v]++;
  }
  // 拓扑排序
  for (int i = 1; i <= n; ++i)
    if (!t[i]) q.push(i);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto [v, w] : adj[u]) {
      s[v] = max(s[v], s[u] + w);
      t[v]--;
      if (!t[v]) q.push(v);
    }
  }
  for (int i = 1; i <= n; ++i) cout << s[i] << '\n';
}
